<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%request.setAttribute("ctx", request.getContextPath());%>
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap.min.css">
    <link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="<%=request.getContextPath() %>/css/theme.blue.css" type="text/css"></link>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.validate.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/my.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath() %>/js/jquery.tablesorter.js"></script>
    <script type="text/javascript">
        /*js代码区*/
    </script>
</head>
<body>
<br>
<br>
<br>
<br>
<br>
<br>
<div class="col-md-12">
    <div class="page-header">
        <h2>
            <small>页面说明</small><br>
        </h2>
    </div>
    ${pageInfo}
    <div class="col-md-12">
        <form action="/kccheck/list" method="get">
            欢迎你:${user.username}<br>
            <a href="/kccheck/show">选课明细</a><br>
            课程名称:<select id="class" name="jqSelect" ></select>
            <input type="text" id="name" name="name" value="${kc.name}">
            <input type="submit" value="查询" >
        </form>
        学生选课系统-选课

        <table id="myTable" class="tablesorter-blue">
            <%--表头部分--%>
            <thead>
            <tr>
                <td>课程id</td>
                <td>课程名称</td>
                <td>教师姓名</td>
                <td>课程时间</td>
                <td>课程地点</td>
                <td>操作</td>
            </tr>
            </thead>

            <%--表格内容部分--%>
            <c:forEach items="${pageInfo.list}" var="l" varStatus="o">
                <tr>
                    <td>${o.index+1}</td>
                    <td>${l.kcName}</td>
                    <td>${l.teacher}</td>
                    <td>${l.time}</td>
                    <td>${l.address}</td>
                    <td>
                        <input type="button" value="选课" onclick="checkKc(${l.kcId})">
                    </td>
                </tr>
            </c:forEach>
            <tr>
                <td colspan="15">
                    <div class="col-md-12">
                        <%--分页部分--%>
                        <ul class="pagination">
                            <%--首页--%>
                            <li class="page-item"><a class="page-link"
                                                     href="/kc/list?pageSize=${pageInfo.pageSize}&pageNum=1&jqSelect=${kc.jqSelect}&name=${kc.name}">首页</a>
                            </li>

                            <c:if test="${!pageInfo.isFirstPage}">
                                <%--上一页--%>
                                <li class="page-item">
                                    <a class="page-link"
                                       href="/kc/list?pageSize=${pageInfo.prePage}&pageNum=${pageInfo.pageNum}&jqSelect=${kc.jqSelect}&name=${kc.name}"><span>&laquo;</span></a>
                                </li>
                            </c:if>


                            <c:forEach items="${pageInfo.navigatepageNums}" var="item">
                                <%--导航条区域--%>
                                <c:if test="${pageInfo.pageNum == item}">
                                    <li class="page-item active">
                                </c:if>
                                <c:if test="${pageInfo.pageNum != item}">
                                    <li class="page-item">
                                </c:if>
                                <a class="page-link"
                                   href="/kc/list?pageSize=${pageInfo.pageSize}&pageNum=${item}&jqSelect=${kc.jqSelect}&name=${kc.name}">${item}</a>
                                </li>
                            </c:forEach>

                            <c:if test="${!pageInfo.isLastPage}">
                                <%--下一页--%>
                                <li class="page-item">
                                    <a class="page-link"
                                       href="/kc/list?pageSize=${pageInfo.nextPage}&pageNum=${pageInfo.pageNum}&jqSelect=${kc.jqSelect}&name=${kc.name}"><span>&raquo;</span></a>
                                </li>
                            </c:if>
                            <%--尾页--%>
                            <li class="page-item"><a class="page-link"
                                                     href="/kc/list?pageSize=${pageInfo.pageSize}&pageNum=${pageInfo.pages}&jqSelect=${kc.jqSelect}&name=${kc.name}">尾页</a>
                            </li>
                        </ul>
                        <h2>共 ${pageInfo.total} 条数据,共 ${pageInfo.pages} 页</h2>
                    </div>
                </td>
            </tr>

        </table>

    </div>
</div>
</body>
<script type="text/javascript">
    $("#myTable").tablesorter()

    // function selectAll(){
    //     var jqSelect = $("#jqSelect").val();
    //     var name = $("#name").val();
    // }
    $(function () {
        $.post("/kc/selectName",function (result){
            for (var i = 0; i < result.length; i++) {

                $("#class").append("<option value='"+result[i].id+"'>"+result[i].name+"</option>")
            }
        },"json")

    })

    function checkKc(id){
        $.post("/kc/checkKc?id="+id,function (result){
            if (result==-1){
                alert("您已选择过该课程,已为您刷新");
            }
            if (result != -1){
                alert("选课成功");
            }
        },"text")
    }
</script>
</html>